<?php
//by willson 105328468@qq.com 2014/10/11
//index page interface

class weixin extends core {

	public function __construct() {
		parent::__construct();
	}

	//列表
	public function menu() {
		include(ROOT_PATH.'/wxapi/config.php');
		$obj = new wechatCallbackAPI();
		if (IS_POST) {
			$access_token = (isset($_POST['access_token'])) ? trim($_POST['access_token']) : '';
			$menu = (isset($_POST['menu'])) ? trim($_POST['menu']) : '';
			$menu = stripslashes($menu);
			$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$access_token}";
			$html = $obj->postData($url, $menu);
			$json = json_decode($html);
			header("Location:?app=weixin&act=menu&msg=1");
		} else {
			$msg = (isset($_GET['msg'])) ? intval($_GET['msg']) : 0;
			$access_token = $obj->access_token();
			$html = file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={$access_token}");
			//echo $html;
			//exit;
			$json = json_decode($html);
			$menu = $json->menu;
			$menu = $obj->formatJSON($menu);
			$this->smarty->assign('menu', $menu);
			$this->smarty->assign('msg', $msg);
			$this->smarty->assign('access_token', $access_token);
			$this->display();
		}		
	}

}
